package defiant.common.tools;

import static defiant.common.tools.Logger.log;
import static defiant.common.tools.SysProperties.WEB_SERVER_PORT;

import org.apache.velocity.app.Velocity;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

public class WebServer {
	final Server server = new Server();
	final Connector connector = new SelectChannelConnector();
	
	public void run() {
    	
    	
    	connector.setPort(WEB_SERVER_PORT);
    	
    	server.setConnectors(new Connector[] { connector });
    	final WebAppContext webappcontext = new WebAppContext();
    	webappcontext.setContextPath("");
    	webappcontext.setWar("WebContent");
    	server.setHandler(webappcontext);
    	
    	try {
			server.start();
		} catch (Exception e) {
			log(new Exception("Web server failed to start!", e));
		}
	}
	
	public void stop() {
		try {
			server.stop();
			connector.close();
		} catch (Exception e) {
			log(new Exception("Web server failed to stop!", e));
		}
	}
}
